﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.Unity;

namespace Website.Core.Filters
{
    public class BrowserDetectionFilter: IResultFilter
    {
        private IUnityContainer _container;

        // Test for IoC
        public BrowserDetectionFilter(IUnityContainer container)
        {
            _container = container;
        }

        #region IResultFilter Members

        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            StringBuilder result = new StringBuilder();
            result.Append("<div style=\"width:200px; border:1px #fff solid;color:#fff;margin:0 auto;padding:5px;\">");
            result.Append(string.Format("<div><b>Browser Type</b>: {0}</div>", filterContext.HttpContext.Request.Browser.Browser));
            result.Append(string.Format("<div><b>Version</b>: {0}</div>", filterContext.HttpContext.Request.Browser.Version));
            result.Append("</div>");

            filterContext.HttpContext.Response.Write(result.ToString());
        }

        public void OnResultExecuting(ResultExecutingContext filterContext) {}

        #endregion
    }
}
